﻿using CommunicationProtocol.dto;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace monoClient.utils
{
    public class ImageUtils
    {
        private static ConcurrentDictionary<int, List<Texture2D>> imageCache = new ConcurrentDictionary<int, List<Texture2D>>();

        public static List<Texture2D> loadImagesByObjectType(int objectType) {

            List<Texture2D> result;
            if (imageCache.TryGetValue(objectType, out result))
            {

                Console.WriteLine(objectType + " 缓存命中");
                return result;
            }

            throw new ArgumentException($"不支持创建对象类型为{objectType}的对象");


            
        }

     
        
        internal static void loadCache(ContentManager content)
        {
            imageCache.TryAdd(1, load(content, "peaShooter", 15));


            imageCache.TryAdd(2,load(content, "sunFlower", 19));
            
        }

        internal static List<Texture2D> load(ContentManager content,string floderName,int count) {

            List<Texture2D> result = new List<Texture2D>();
            for (int i = 0; i < count; i++)
            {
                result.Add(
                    content.Load<Texture2D>($"{floderName}\\{i}")
                    );
            }

            return result;
        }
    }
}
